package org.jaychan.live.user.provider;


import jakarta.annotation.Resource;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.jaychan.live.user.constants.UserTagsEnum;
import org.jaychan.live.user.dto.UserDTO;
import org.jaychan.live.user.provider.service.IUserService;
import org.jaychan.live.user.provider.service.IUserTagService;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

import java.util.concurrent.CountDownLatch;
import java.util.logging.Logger;


@SpringBootApplication
@EnableDubbo
@EnableDiscoveryClient
public class UserProviderApplication implements CommandLineRunner {


    @Resource
    private IUserTagService userTagService;
    @Resource
    private IUserService userService;

    public static void main(String[] args) {
        SpringApplication springApplication = new SpringApplication(UserProviderApplication.class);
        springApplication.setWebApplicationType(WebApplicationType.NONE);
        springApplication.run(args);
    }

    @Override
    public void run(String... args) throws Exception {
//        Long userId = 1004L;
//
//
//        //测试，让100个线程同时取跑这个方法
//        //首先创建了一个计数为1的CountDownLatch对象count。
//        //然后使用for循环创建了100个线程t1，每个线程会执行run()方法。
//        //在run()方法中，线程会调用count.await()方法等待计数器变为0，然后继续执行打印语句。
//        //最后，在所有线程启动后，主线程调用count.countDown()方法将计数器减1，使得所有等待的线程可以继续执行。
//        //这段代码的作用是让100个线程同时等待，直到主线程发出信号后才一起执行打印语句
//
//        CountDownLatch count = new CountDownLatch(1);
//        for (int i = 0; i < 100; i++) {
//            Thread t1 = new Thread(new Runnable() {
//                @Override
//                public void run() {
//                    try {
//                        count.await();
//                        System.out.println("result is " + userTagService.setTag(userId,UserTagsEnum.IS_VIP));
//
//                    } catch (InterruptedException e) {
//                        throw new RuntimeException(e);
//                    }
//                }
//            });
//            t1.start();
//
//        }
//
//        count.countDown();
//        Thread.sleep(100000L);

//
//        UserDTO userDTO = userService.getByUserid(userId);
////        userDTO.setNickName("jay-change-test222");
////        userService.updateUserInfo(userDTO);
////        System.out.println(userTagService.cancelTag(userId,UserTagsEnum.IS_OLD_USER));
//
//        System.out.println(userTagService.containTag(userId,UserTagsEnum.IS_OLD_USER));
////        System.out.println(userTagService.setTag(userId,UserTagsEnum.IS_OLD_USER));
////        System.out.println(userTagService.containTag(userId,UserTagsEnum.IS_OLD_USER));
//

    }
}
